function HandleProduces(gui, item, options) {
  this._gui = gui;
  this._item = item;
  this._options = options;
  
  this._query = (options && options.query) ? options.query : null;
  this._operator = (options && options.operator) ? options.operator : null;
  this._now = (options && options.now) ? options.now : null;
  this._menu = (options && options.menu) ? options.menu : null;
  this._smryGui = (options && options.smryGui) ? options.smryGui : null;
  this._smryArgs = (options && options.smryArgs) ? options.smryArgs : null;
  this._isDeadLine = (options && options.a) ? options.a : 0;
  
  this._nopage = (options && options.nopage) ? options.nopage : null;
  this._multiple = (options && options.multiple) ? options.multiple : null;
  this._multiple2 = (options && options.multiple2) ? options.multiple2 : null;
  this._noExist = (options && options.noExist) ? options.noExist : false;
  this._isSupervise = (options && options.s) ? options.s : 0;
  this._isfromcus = (options && options.isfromcus) ? options.isfromcus : false;
  
  this._createElements();
};

HandleProduces.prototype._createElements = function() {
  this._loadData();
};

HandleProduces.prototype._verifyData = function() {
  if (this._produces && this._events) {
    this._updateElements();
  }
};

HandleProduces.prototype._loadData = function() {
  this._produces = null;
  this._events = null;
  this._retrieveProduces();
  this._retrieveEvents();
};

HandleProduces.prototype._retrieveProduces = function(page, condition, pos) {
  var _self = this;
  condition = (condition) ? condition.replace('d.branch = \'{{$smarty.const.BRANCH|escape:javascript}}\' AND ' + this._query + ' AND ', '') : '';
  if (this._isDeadLine) {
    var joins = '&selects=1' + '&purchaseitems=1' + '&preconusers=0' + '&events=1' + '&tracks=0' + '&produces=0' + '&notes=1';
    var args = '&c=d.branch = \'{{$smarty.const.BRANCH|escape:javascript}}\' AND (' + this._query + ')' + ((condition) ? (' AND (' + condition + ')') : '') + '&p=' + ((page) ? page : 1) + '&s=' + ((this._nopage) ? '9999' : DlmanageUtils.number) + '&o=d.deadline' + '&q=ASC' + '&line=' + this._isDeadLine + joins;
    new RequestUtils()._mysql('produce', args, function(result, params) { _self._produces = result.data;
                                                                            _self._parameters = result;
                                                                            _self._verifyData.call(_self);
                                                                          }, { php: Constant.FACTORY + '/customphp/produceread.php', pos: pos });
  } else {
    var joins = '&selects=1' + '&purchaseitems=1' + '&preconusers=0' + '&events=1' + '&tracks=0' + '&produces=0' + '&notes=1';
    var args = '&c=d.branch = \'{{$smarty.const.BRANCH|escape:javascript}}\' AND (' + this._query + ')' + ((condition) ? (' AND (' + condition + ')') : '') + '&p=' + ((page) ? page : 1) + '&s=' + ((this._nopage) ? '9999' : DlmanageUtils.number) + '&o=d.deadline' + '&q=ASC' + joins;
    new RequestUtils()._mysql('produce', args, function(result, params) { _self._produces = result.data;
                                                                           _self._parameters = result;
                                                                           _self._verifyData.call(_self);
                                                                          }, { php: Constant.FACTORY + '/customphp/produceread.php', pos: pos });
  }
};

HandleProduces.prototype._retrieveEvents = function(pos) {
  var _self = this;
  if (this._noExist || this._isSupervise || this._multiple) {
    this._events = [];
  } else {
    var args = '&operator=' + JSON.stringify(this._operator) + '&b=' + JSON.stringify('{{$smarty.const.BRANCH|escape:javascript}}');
    new RequestUtils()._mysql('produceevent', args, function(result, params) { _self._events = result.data;
                                                                               _self._verifyData.call(_self);
                                                                             }, { php: Constant.FACTORY + '/customphp/mysqlcustom.php', pos: ((pos) ? pos : null)});
  }
};

HandleProduces.prototype._updateElements = function() {
  var _self = this;
  DOMUtils.removeChildElements(this._gui.pages);
  DOMUtils.removeChildElements(this._gui.tasks);

  if (this._smryGui && this._smryArgs) {
    new HandleSmry(this._smryGui, null, { args: this._smryArgs, a: this._isDeadLine });
  }
  
  var gui = GuiSearchTask.instance(this._gui.customerNo, this._gui.task, this._gui.search);
  new HandleSearchTask(gui, this._item, { callbackFunc: function(condition) { _self._retrieveProduces.call(_self, 1, condition); }, query: 'd.branch = \'{{$smarty.const.BRANCH|escape:javascript}}\' AND (' + this._query + ')' });
  
  if (!this._nopage) {
    Pagination.makePagedResults(this._gui.pages, this._parameters.page, this._parameters.total, this._parameters.size, function(page, condition) { _self._retrieveProduces.call(_self, page, _self._parameters.condition); }, this, document);
  }
  
  if (this._multiple) {
    if (this._operator.type == '{{$smarty.const.USER_TYPE_MANAGER_ASSISTANT|escape:javascript}}') {
      this._mailing = [];
      this._gui.mail.onclick = function() { if (_self._mailing.length > 0) {
                                              location.href = '?p=pageasst&t=pagemailinformation&m=' + JSON.stringify({a:1, b:1, c:1, d:17}) + '&opts=' + JSON.stringify({ p: DlmanageUtils.identifiers(_self._mailing) });
                                            }
                                          };
    } else if (this._operator.type == '{{$smarty.const.USER_TYPE_MANAGER|escape:javascript}}') {
      this._mailing = [];
      this._gui.mail.onclick = function() { if (_self._mailing.length > 0) {
                                              location.href = '?p=pagemanager&t=pagemailinformation&m=' + JSON.stringify({a:1, b:2, c:14}) + '&s=' + JSON.stringify({s: 2}) + '&opts=' + JSON.stringify({ p: DlmanageUtils.identifiers(_self._mailing)});
                                            }
                                          };
    } else if (this._operator.type == '{{$smarty.const.USER_TYPE_ADMIN|escape:javascript}}') {
      this._mailing = [];
      this._gui.mail.onclick = function() { if (_self._mailing.length > 0) {
                                              location.href = '?p=pageadmin&t=pagemailinformation&m=' + JSON.stringify({a:1, b:4, c:1}) + '&opts=' + JSON.stringify({ p: DlmanageUtils.identifiers(_self._mailing)});
                                            }
                                          };
    } else {
      this._gui.mail.style.display = 'none';
    }
    new TableProducesMailing(this._gui.tasks, this._produces, { user: this._operator, date: this._now, produces: this._mailing, hidePrice: true, callbackFunc: function() { _self._retrieveProduces.call(_self); } });
  } if (this._multiple2) {
    if (this._operator.type == '{{$smarty.const.USER_TYPE_MANAGER_ASSISTANT|escape:javascript}}') {
      this._mailing = [];
      this._gui.mail.onclick = function() { if (_self._mailing.length > 0) {
                                              location.href = '?p=pageasst&t=pagetapesparcel&m=' + JSON.stringify({a:1, b:1, c:1, d:17}) + '&opts=' + JSON.stringify({ p: DlmanageUtils.identifiers(_self._mailing), b: '{{$smarty.const.BRANCH|escape:javascript}}', t: 'pageb1sendtape' });
                                            }
                                          };
    } else if (this._operator.type == '{{$smarty.const.USER_TYPE_MANAGER|escape:javascript}}') {
      this._mailing = [];
      this._gui.mail.onclick = function() { if (_self._mailing.length > 0) {
                                              location.href = '?p=pagemanager&t=pagetapesparcel&m=' + JSON.stringify({a:1, b:2, c:14}) + '&s=' + JSON.stringify({s: 2}) + '&opts=' + JSON.stringify({ p: DlmanageUtils.identifiers(_self._mailing), b: '{{$smarty.const.BRANCH|escape:javascript}}', t: 'pageb1sendtape' });
                                            }
                                          };
    } else if (this._operator.type == '{{$smarty.const.USER_TYPE_ADMIN|escape:javascript}}') {
      this._mailing = [];
      this._gui.mail.onclick = function() { if (_self._mailing.length > 0) {
                                              location.href = '?p=pageadmin&t=pagetapesparcel&m=' + JSON.stringify({a:1, b:4, c:1}) + '&opts=' + JSON.stringify({ p: DlmanageUtils.identifiers(_self._mailing), b: '{{$smarty.const.BRANCH|escape:javascript}}', t: 'pageb1sendtape' });
                                            }
                                          };
    } else {
      this._gui.mail.style.display = 'none';
    }
    new TableProducesMailing(this._gui.tasks, this._produces, { user: this._operator, date: this._now, produces: this._mailing, hidePrice: true, callbackFunc: function() { _self._retrieveProduces.call(_self); } });
  } else {
    new TableProduces(this._gui.tasks, this._produces, { user: this._operator, date: this._now, callbackFunc: function(pos) { _self._retrieveProduces.call(_self,  _self._parameters.page, _self._parameters.condition, pos); _self._retrieveEvents(); }, hidePrice: true, menu: this._menu, events: this._events, updated: this._gui.updated, noExist: this._noExist, s: this._isSupervise, isfromcus: this._isfromcus, callback: function(pos) { _self._retrieveEvents(pos); } });
  }
};